package com.theo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.theo.entity.FactInfo;
import com.theo.entity.RumourInfo;
import com.theo.service.RumourInfoService;
import com.theo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Controller
@RequestMapping("/rumour-info")
public class RumourInfoController {

    @Autowired
    private RumourInfoService rumourInfoService;
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/show.do")
    public String show(Model model, @RequestParam(value = "pn", defaultValue = "1") Integer pn) {
        PageHelper.startPage(pn, 8);
        List<RumourInfo> list = rumourInfoService.queryAllRumourInfo();
        PageInfo pageInfo = new PageInfo(list, 2);
        model.addAttribute("pageInfo", pageInfo);
        return "admin/rumour_list";
    }

    @RequestMapping("/toInput.do")
    public String toInput() {
        return "admin/rumour_input";
    }
    @RequestMapping("/input.do")
    public String input(RumourInfo rumourInfo) {
        rumourInfoService.saveRumourInfo(rumourInfo);
        return "redirect:/refutation-info/show";
    }
    @RequestMapping("/update.do")
    public String update(RumourInfo rumourInfo) {
        rumourInfoService.updateRumourInfo(rumourInfo);
        return "redirect:/rumour-info/show.do";
    }

    @RequestMapping("/delete.do")
    public String delete(Integer id) {
        rumourInfoService.deleteRumourInfo(id);
        return "redirect:/rumour-info/show.do";
    }
}

